package com.ruoyi.web.controller.dgw;

import java.util.List;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dgw.domain.VaccineApplicat;
import com.ruoyi.dgw.service.IVaccineApplicatService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 疫苗申请Controller
 *
 * @author ruoyi
 * @date 2021-11-17
 */
@RestController
@RequestMapping("/dgw/applicat")
@Slf4j
public class VaccineApplicatController extends BaseController {
    @Autowired
    private IVaccineApplicatService vaccineApplicatService;

    /**
     * 查询疫苗申请列表
     */
    @PreAuthorize("@ss.hasPermi('dgw:applicat:list')")
    @GetMapping("/list")
    public TableDataInfo list(VaccineApplicat vaccineApplicat) {
        startPage();
        List<VaccineApplicat> list = vaccineApplicatService.selectVaccineApplicatList(vaccineApplicat);
        return getDataTable(list);
    }

    /**
     * 导出疫苗申请列表
     */
    @PreAuthorize("@ss.hasPermi('dgw:applicat:export')")
    @Log(title = "疫苗申请", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(VaccineApplicat vaccineApplicat) {
        List<VaccineApplicat> list = vaccineApplicatService.selectVaccineApplicatList(vaccineApplicat);
        ExcelUtil<VaccineApplicat> util = new ExcelUtil<VaccineApplicat>(VaccineApplicat.class);
        return util.exportExcel(list, "疫苗申请数据");
    }

    /**
     * 获取疫苗申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('dgw:applicat:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(vaccineApplicatService.selectVaccineApplicatById(id));
    }

    /**
     * 新增疫苗申请
     */
    @PreAuthorize("@ss.hasPermi('dgw:applicat:add')")
    @Log(title = "疫苗申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VaccineApplicat vaccineApplicat) {
        return toAjax(vaccineApplicatService.insertVaccineApplicat(vaccineApplicat));
    }

    /**
     * 修改疫苗申请
     */
    @PreAuthorize("@ss.hasPermi('dgw:applicat:edit')")
    @Log(title = "疫苗申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VaccineApplicat vaccineApplicat) {
        return toAjax(vaccineApplicatService.updateVaccineApplicat(vaccineApplicat));
    }

    /**
     * 删除疫苗申请
     */
    @PreAuthorize("@ss.hasPermi('dgw:applicat:remove')")
    @Log(title = "疫苗申请", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(vaccineApplicatService.deleteVaccineApplicatByIds(ids));
    }

    @PreAuthorize("@ss.hasPermi('dgw:applicat:updateStatus')")
    @Log(title = "疫苗审批", businessType = BusinessType.UPDATE)
    @PutMapping("/updateStatus")
    public AjaxResult updateStatus(@RequestBody VaccineApplicat vaccineApplicat) {
        return toAjax(vaccineApplicatService.updateStatus(vaccineApplicat.getId(), vaccineApplicat.getStatusBy()));
    }
}
